﻿using SRB.Tg.DrawingStandard;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class ModelTablePloter
    {
        static string _dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarGrade.dwg";
        static double rowH = 6;
        static bool isCopy = false;
        static string oldBlockName = "OneGrade";
        /// <summary>
        /// 承台钢筋明细表格
        /// </summary>
        /// <param name="db"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        /// <param name="tbHeight"></param>
        /// <param name="tbWidth"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        ///  <param name="isHaveNetRebar">是否有钢筋网</param>
        public static void DrawCapRebarTable(Database db, ref Extents2d ext, Point3d startPoint, System.Data.DataTable dt, List<string> headName,
            int rowNum, int colNum, ref double tbHeight,ref double tbWidth, string txtStyle, double scale, bool isHaveNetRebar = false,int netNum=2)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                ObjectId gjGradeId = st["SRB.tssdeng"];
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                //tb.SetColumnWidth(50);
                //tb.Width = tbWidth;
                //tb.Height = tbHeight;
             
                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                tb.Rows[0].Height = 10 * scale;
               
                        
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    // 设置表数据    
                    string strNo = "N"+ dt.Rows[i]["no"].ToString().Replace("N","");                                     // 钢筋编号
                    string strDiameter = "Ф"+ dt.Rows[i]["diameter"].ToString();                         // 直径
                    string strProbably_length = dt.Rows[i]["probably_length"].ToString();           // 大样
                    string strLength =(double.Parse(dt.Rows[i]["length"].ToString())/10).ToString()+ "\r    ";                             // 单根长
                    string strNum = dt.Rows[i]["number"].ToString();                                // 数量
                    string strTotal_length = double.Parse(dt.Rows[i]["total_length"].ToString()).ToString("0.00") + "\r    ";                 // 总长
                    string strSingle_weight = dt.Rows[i]["single_weight"].ToString() + "\r    ";               // 单重
                    string strTotal_weight = dt.Rows[i]["total_weight"].ToString() + "\r    ";                 // 总重
                    if (headName.Contains("大样"))
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = strProbably_length; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 7].TextString = strTotal_weight; //获取i行j列数据
                    }
                    else
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strTotal_weight; //获取i行j列数据
   
                    }
                    string _blcName = "OneGrade";
                    switch(dt.Rows[i]["diameter"].ToString())
                    {
                        //case "HRB300":
                        //    _blcName = "OneGrade";
                        //    strDiameter= "%%130" + dt.Rows[i]["diameter"].ToString();
                        //    break;
                        //case "HRB335":
                        //    _blcName = "TwoGrade";
                        //    strDiameter = "%%131" + dt.Rows[i]["diameter"].ToString();
                        //    break;
                        //case "HRB400":
                        //    _blcName = "ThreeGrade";
                        //    strDiameter = "%%132" + dt.Rows[i]["diameter"].ToString();
                        //    break;
                        //case "HRB500":
                        //    _blcName = "FourGrade";
                        //    strDiameter = "%%133" + dt.Rows[i]["diameter"].ToString();
                        //    break;
                        case "HRB300":
                            _blcName = "OneGrade";
                            strDiameter = "A" + dt.Rows[i]["diameter"].ToString();
                            break;
                        case "HRB335":
                            _blcName = "TwoGrade";
                            strDiameter = "B" + dt.Rows[i]["diameter"].ToString();
                            break;
                        case "HRB400":
                            _blcName = "ThreeGrade";
                            strDiameter = "C" + dt.Rows[i]["diameter"].ToString();
                            break;
                        case "HRB500":
                            _blcName = "FourGrade";
                            strDiameter = "D" + dt.Rows[i]["diameter"].ToString();
                            break;
                    }

                  

                    Point3d ptGJGrade = startPoint.C3D(20 * scale + 20 * scale * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid,"H文本");

                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = rowH * scale;
                    int num = colNum;
                    if (headName.Contains("小计(kg)"))
                        num = colNum - 1;
                    for (int j = 0; j < num; ++j)
                    {
                        tb.Cells[i, j].Contents[0].TextHeight = 2.5 * scale;
                        if (headName.Contains("大样"))
                        {
                            if (j > 2 && j != 4)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleRight;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;                        
                        }
                        else
                        {
                            if (j > 1 && j != 3)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleRight;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        }
                        tb.Cells[i, j].Contents[0].Rotation = 0;
                        tb.Cells[i, j].Borders.Horizontal.Margin = 2 * scale;
                        if (j == 1)
                        {
                            //tb.Cells[i, j].Contents[0].TextStyleId = gjGradeId;
                        }
                        else
                            tb.Cells[i, j].Contents[0].TextStyleId = id;
                        
                    }
                }

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (headName.Contains("大样"))
                    {
                        if (i > 2)
                            tb.Columns[i].Width = 15 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                    else
                    {
                        if (i > 1)
                            tb.Columns[i].Width = 15 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                }

                #region 绘制大样
                if (headName.Contains("大样"))
                {
                    Point2d pt = tb.Position.C2D(20 * scale * 2 + 1 * scale, -5 * scale - tb.Rows[0].Height);
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        Polyline line = new Polyline() { Closed = false, LayerId = st["H粗线"], ColorIndex = 1 };//定义不封闭的Polyline 平面虚线
                        if (isHaveNetRebar && i > dt.Rows.Count - netNum-1)
                        {
                            line.AddVertexAt(0, pt.C2D(0, -i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                            line.AddVertexAt(1, pt.C2D(18 * scale, -i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                        }
                        else
                        {
                            line.AddVertexAt(0, pt.C2D(0, 2 * scale - i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                            line.AddVertexAt(1, pt.C2D(0, -i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                            line.AddVertexAt(2, pt.C2D(18 * scale, -i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                            line.AddVertexAt(3, pt.C2D(18 * scale, 2 * scale - i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                        }
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                    }
                }
                #endregion

                #region 列单元格合并
                if (headName.Contains("小计(kg)"))
                {
                    // 数据排序
                    Dictionary<int, int> dic = new Dictionary<int, int>();
                    int rowIndex = 0;
                    int num = 0;
                    string stDia = dt.Rows[0]["diameter"].ToString();
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        if (dt.Rows[i]["diameter"].ToString() == stDia)
                        {
                            num++;
                        }
                        else
                        {
                            dic.Add(rowIndex, num);
                            num = 1;
                            rowIndex = i;
                            stDia = dt.Rows[i]["diameter"].ToString();

                        }
                        if (i == dt.Rows.Count - 1)
                            dic.Add(rowIndex, num);
                    }

                    // 列单元格合并
                    int topRow = 1;

                    List<CellRange> cellList = new List<CellRange>();

                    foreach (KeyValuePair<int, int> pr in dic)
                    {
                        double weight = 0.0;
                        for (int i = 0; i < pr.Value; ++i)
                        {
                            weight += double.Parse(tb.Cells[i + topRow, tb.Columns.Count - 2].Value.ToString());
                        }

                        tb.Cells[topRow, tb.Columns.Count - 1].TextString = weight.ToString(); //获取i行j列数据
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].Rotation = 0;
                        tb.Cells[topRow, tb.Columns.Count - 1].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextStyleId = id;

                        CellRange range = CellRange.Create(tb, topRow, tb.Columns.Count - 1, topRow + pr.Value - 1, tb.Columns.Count - 1);
                        cellList.Add(range);
                        topRow += pr.Value;
                    }
                    foreach (CellRange range in cellList)
                    {
                        tb.MergeCells(range);
                    }
                }
                #endregion


                tb.LayerId = st["H细线"];
                modelSpace.AppendEntity(tb);
               
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();

           
                //return tb.Height;
            }
        }
        /// <summary>
        /// 材料数量明细表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="dt"></param>
        /// <param name="headName"></param>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        /// <param name="tbHeight"></param>
        /// <param name="tbWidth"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        public static void DrawCapMaterialsTable(Database db, ref Extents2d ext, Point3d startPoint, System.Data.DataTable dt, List<string> headName,
            int rowNum, int colNum, ref double tbHeight,ref double tbWidth, string txtStyle, double scale)
        {
            double width = 0;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 3 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                tb.Rows[0].Height = 8 * scale;
                #region 数据排序
                // 数据排序
                Dictionary<string, List<int>> dic = new Dictionary<string, List<int>>();
                for (int i = 0; i < dt.Rows.Count; ++i)
                {
                    string strNo = dt.Rows[i]["name"].ToString();
                    if (dic.Count == 0)
                    {
                        List<int> list = new List<int>();
                        list.Add(i);
                        dic.Add(strNo, list);
                    }
                    else
                    {
                        if (!dic.ContainsKey(strNo))
                        {
                            List<int> list = new List<int>();
                            list.Add(i);
                            dic.Add(strNo, list);
                        }
                        else
                        {
                            List<int> list = new List<int>();
                            dic.TryGetValue(strNo, out list);
                            list.Add(i);
                            dic[strNo] = list;
                        }
                    }
                }
                #endregion

                #region 表格添加数据
                int index = 0;
                foreach (KeyValuePair<string, List<int>> pr in dic)
                {
                    // 设置表数据
                    for (int i = 0; i < pr.Value.Count; ++i)
                    {
                        string strNo = dt.Rows[pr.Value[i]]["name"].ToString();                                     // 钢筋编号
                        string strDiameter = dt.Rows[pr.Value[i]]["standard"].ToString();                         // 直径
                        string strProbably_length = dt.Rows[pr.Value[i]]["unit"].ToString();           // 大样
                        string strLength = dt.Rows[pr.Value[i]]["total"].ToString();                             // 单根长
                        string strNum = dt.Rows[pr.Value[i]]["summary"].ToString();                                // 数量

                        tb.Cells[index + i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[index + i + 1, 1].TextString = strDiameter; //获取i行j列数据
                        tb.Cells[index + i + 1, 2].TextString = strProbably_length; //获取i行j列数据
                        tb.Cells[index + i + 1, 3].TextString = strLength; //获取i行j列数据
                        tb.Cells[index + i + 1, 4].TextString = strNum; //获取i行j列数据
                    }
                    index += pr.Value.Count;
                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 6;
                    for (int j = 0; j < colNum - 1; ++j)
                    {
                        if (tb.Cells[i, j].Contents != null && tb.Cells[i, j].Contents.Count > 0)
                        {
                            tb.Cells[i, j].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[i, j].Contents[0].Rotation = 0;
                            tb.Cells[i, j].Contents[0].TextStyleId = id;
                        }
                        tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, j].Borders.Horizontal.Margin = 2 * scale;
                    }
                }
                #endregion

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 1 || i == 2)
                    {
                        tb.Columns[i].Width = 15 * scale;
                    }
                    else
                    {
                        tb.Columns[i].Width = 25 * scale;
                    }
                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 6 * scale;
                }

                #region 列单元格合并
                // 列单元格合并
                int topRow = 1;
                int bottomRow = 1;
                int leftCol = 1;
                int rightCol = 1;
       

                List<CellRange> cellList = new List<CellRange>();

                foreach (KeyValuePair<string, List<int>> pr in dic)
                {
                    double weight = 0.0;
                    for (int i = 0; i < pr.Value.Count; ++i)
                    {
                        double v = 0; 
                        double.TryParse(tb.Cells[i + topRow, 3].Value.ToString(),out v);
                        weight +=v ;
                    }
                    tb.Cells[topRow, 4].TextString = weight.ToString(); //获取i行j列数据
                    tb.Cells[topRow, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[topRow, 4].Borders.Horizontal.Margin = 2 * scale;
                    if (tb.Cells[topRow, 4].Contents != null && tb.Cells[topRow, 4].Contents.Count > 0)
                    {
                        tb.Cells[topRow, 4].Contents[0].Rotation = 0;
                        tb.Cells[topRow, 4].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[topRow, 4].Contents[0].TextStyleId = id;
                    }

                    // 总重合计项
                    CellRange range = CellRange.Create(tb, topRow, 4, topRow + pr.Value.Count - 1, 4);
                    cellList.Add(range);

                    // 名称
                    CellRange range2 = CellRange.Create(tb, topRow, 0, topRow + pr.Value.Count - 1, 0);
                    cellList.Add(range2);

                    topRow += pr.Value.Count;
                }
                if (dt.Rows.Count > 0)
                {
                    // 合并单位
                    topRow = 1;
                    bottomRow = 1;
                    string unit = tb.Cells[1, 2].Value.ToString();
                    for (int i = 2; i < rowNum; ++i)
                    {
                        string str = tb.Cells[i, 2].Value.ToString();
                        if (str == unit)
                        {
                            bottomRow = i;
                            if (i == rowNum - 1)
                            {
                                CellRange range = CellRange.Create(tb, topRow, 2, bottomRow, 2);
                                cellList.Add(range);
                            }
                        }
                        else
                        {
                            CellRange range = CellRange.Create(tb, topRow, 2, bottomRow, 2);
                            cellList.Add(range);

                            unit = str;
                            topRow = i;
                            bottomRow = i;
                        }
                    }

                    // 合并表头
                    leftCol = 0;
                    rightCol = 0;
                    string title = tb.Cells[0, 0].Value.ToString();
                    for (int i = 1; i < colNum; ++i)
                    {
                        string str = tb.Cells[0, i].Value.ToString();
                        if (str == title)
                        {
                            rightCol = i;
                            if (i == colNum - 1)
                            {
                                CellRange range = CellRange.Create(tb, 0, leftCol, 0, rightCol);
                                cellList.Add(range);
                            }
                        }
                        else
                        {
                            CellRange range = CellRange.Create(tb, 0, leftCol, 0, rightCol);
                            cellList.Add(range);

                            title = str;
                            leftCol = i;
                            rightCol = i;
                        }
                    }
                    foreach (CellRange range in cellList)
                    {
                        tb.MergeCells(range);
                    }
                }
                #endregion
                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();

             
            }
        }


        public static void DrawCushionRebarTable(Database db, ref Extents2d ext, Point3d startPoint, System.Data.DataTable dt, List<string> headName,
    int rowNum, int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, double scale, bool isHaveNetRebar = false, int netNum = 2)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                ObjectId gjGradeId = st["SRB.tssdeng"];
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                //tb.SetColumnWidth(50);
                //tb.Width = tbWidth;
                //tb.Height = tbHeight;

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                tb.Rows[0].Height = 10 * scale;


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    // 设置表数据    
                    string strNo = "N" + dt.Rows[i]["no"].ToString().Replace("N", "");                                     // 钢筋编号
                    string strDiameter = "Ф" + dt.Rows[i]["diameter"].ToString();                         // 直径
                    string strProbably_length = dt.Rows[i]["probably_length"].ToString();           // 大样
                    string strLength = (double.Parse(dt.Rows[i]["length"].ToString()) / 10).ToString() + "\r    ";                             // 单根长
                    string strNum = dt.Rows[i]["number"].ToString();                                // 数量
                    string strTotal_length = double.Parse(dt.Rows[i]["total_length"].ToString()).ToString("0.00") + "\r    ";                 // 总长
                    string strSingle_weight = dt.Rows[i]["single_weight"].ToString() + "\r    ";               // 单重
                    string strTotal_weight = dt.Rows[i]["total_weight"].ToString() + "\r    ";                 // 总重
                    if (headName.Contains("大样"))
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = strProbably_length; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 7].TextString = strTotal_weight; //获取i行j列数据
                    }
                    else
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strTotal_weight; //获取i行j列数据

                    }
                    string _blcName = "OneGrade";
                    switch (dt.Rows[i]["diameter"].ToString())
                    {
                        //case "HRB300":
                        //    _blcName = "OneGrade";
                        //    strDiameter= "%%130" + dt.Rows[i]["diameter"].ToString();
                        //    break;
                        //case "HRB335":
                        //    _blcName = "TwoGrade";
                        //    strDiameter = "%%131" + dt.Rows[i]["diameter"].ToString();
                        //    break;
                        //case "HRB400":
                        //    _blcName = "ThreeGrade";
                        //    strDiameter = "%%132" + dt.Rows[i]["diameter"].ToString();
                        //    break;
                        //case "HRB500":
                        //    _blcName = "FourGrade";
                        //    strDiameter = "%%133" + dt.Rows[i]["diameter"].ToString();
                        //    break;
                        case "HRB300":
                            _blcName = "OneGrade";
                            strDiameter = "A" + dt.Rows[i]["diameter"].ToString();
                            break;
                        case "HRB335":
                            _blcName = "TwoGrade";
                            strDiameter = "B" + dt.Rows[i]["diameter"].ToString();
                            break;
                        case "HRB400":
                            _blcName = "ThreeGrade";
                            strDiameter = "C" + dt.Rows[i]["diameter"].ToString();
                            break;
                        case "HRB500":
                            _blcName = "FourGrade";
                            strDiameter = "D" + dt.Rows[i]["diameter"].ToString();
                            break;
                    }



                    Point3d ptGJGrade = startPoint.C3D(20 * scale + 20 * scale * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    TextPloter.AddDBText(db, ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H文本");

                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = rowH * scale;
                    int num = colNum;
                    if (headName.Contains("小计(kg)"))
                        num = colNum - 1;
                    for (int j = 0; j < num; ++j)
                    {
                        tb.Cells[i, j].Contents[0].TextHeight = 2.5 * scale;
                        if (headName.Contains("大样"))
                        {
                            if (j > 2 && j != 4)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleRight;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        }
                        else
                        {
                            if (j > 1 && j != 3)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleRight;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        }
                        tb.Cells[i, j].Contents[0].Rotation = 0;
                        tb.Cells[i, j].Borders.Horizontal.Margin = 2 * scale;
                        if (j == 1)
                        {
                            //tb.Cells[i, j].Contents[0].TextStyleId = gjGradeId;
                        }
                        else
                            tb.Cells[i, j].Contents[0].TextStyleId = id;

                    }
                }

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (headName.Contains("大样"))
                    {
                        if (i > 2)
                            tb.Columns[i].Width = 15 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                    else
                    {
                        if (i > 1)
                            tb.Columns[i].Width = 15 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                }

                #region 绘制大样
                if (headName.Contains("大样"))
                {
                    Point2d pt = tb.Position.C2D(20 * scale * 2 + 1 * scale, -5 * scale - tb.Rows[0].Height);
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        Polyline line = new Polyline() { Closed = false, LayerId = st["H粗线"], ColorIndex = 1 };//定义不封闭的Polyline 平面虚线
                        if (isHaveNetRebar && i > dt.Rows.Count - netNum - 1)
                        {
                            line.AddVertexAt(0, pt.C2D(0, -i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                            line.AddVertexAt(1, pt.C2D(18 * scale, -i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                        }
                        else
                        {
                            line.AddVertexAt(0, pt.C2D(0, 2 * scale - i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                            line.AddVertexAt(1, pt.C2D(0, -i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                            line.AddVertexAt(2, pt.C2D(18 * scale, -i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                            line.AddVertexAt(3, pt.C2D(18 * scale, 2 * scale - i * 6 * scale), 0, 0.25 * scale, 0.25 * scale);
                        }
                        modelSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                    }
                }
                #endregion

                #region 列单元格合并
                if (headName.Contains("小计(kg)"))
                {
                    // 数据排序
                    Dictionary<int, int> dic = new Dictionary<int, int>();
                    int rowIndex = 0;
                    int num = 0;
                    string stDia = dt.Rows[0]["diameter"].ToString();
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        if (dt.Rows[i]["diameter"].ToString() == stDia)
                        {
                            num++;
                        }
                        else
                        {
                            dic.Add(rowIndex, num);
                            num = 1;
                            rowIndex = i;
                            stDia = dt.Rows[i]["diameter"].ToString();

                        }
                        if (i == dt.Rows.Count - 1)
                            dic.Add(rowIndex, num);
                    }

                    // 列单元格合并
                    int topRow = 1;

                    List<CellRange> cellList = new List<CellRange>();

                    foreach (KeyValuePair<int, int> pr in dic)
                    {
                        double weight = 0.0;
                        for (int i = 0; i < pr.Value; ++i)
                        {
                            weight += double.Parse(tb.Cells[i + topRow, tb.Columns.Count - 2].Value.ToString());
                        }

                        tb.Cells[topRow, tb.Columns.Count - 1].TextString = weight.ToString(); //获取i行j列数据
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].Rotation = 0;
                        tb.Cells[topRow, tb.Columns.Count - 1].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextStyleId = id;

                        CellRange range = CellRange.Create(tb, topRow, tb.Columns.Count - 1, topRow + pr.Value - 1, tb.Columns.Count - 1);
                        cellList.Add(range);
                        topRow += pr.Value;
                    }
                    foreach (CellRange range in cellList)
                    {
                        tb.MergeCells(range);
                    }
                }
                #endregion


                tb.LayerId = st["H细线"];
                modelSpace.AppendEntity(tb);

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


                //return tb.Height;
            }
        }

        public static void DraTable(Database db, ref Extents2d ext, Point3d startPoint,  List<string> headName, 
            int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, double scale,Dictionary<int, List<string>> tbValue)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                int rowNum = 7;
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    if (i == 0)
                    {
                        tb.Cells[0, i].Alignment = CellAlignment.MiddleLeft;
                    }
                    else
                    {
                        tb.Cells[0, i].Alignment = CellAlignment.MiddleRight;
                    }
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                for (int m = 1; m < rowNum; m++)
                {
                    List<string> valueList = new List<string>();
                    try
                    {
                        valueList = tbValue[m];
                        if (valueList.Count > 0)
                        {
                            for (int i = 0; i < colNum; ++i)
                            {
                                tb.Cells[m, i].TextString = valueList[i]; //获取i行j列数据
                                tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                if (i == 0)
                                {
                                    tb.Cells[m, i].Alignment = CellAlignment.MiddleLeft;
                                }
                                else
                                {
                                    tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                }
                                tb.Cells[m, i].Contents[0].Rotation = 0;
                                tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m, i].Contents[0].TextStyleId = id;
                            }
                        }
                    }catch { }
                }
                #region 表格添加数据

                #endregion

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 10*2.5 * scale;
                    else
                        tb.Columns[i].Width = 5* 2.5  * scale;
                }

                for (int i = 0; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }

                tb.LayerId = lt["H细线"];
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();

           
            }
        }


        public static void DrawPileCalTable(Database db, ref Extents2d ext, Point3d startPoint,
        ref double tbHeight, ref double tbWidth, string txtStyle, double scale, List<Tuple<int, eDB, int, double>> rebarLst,string MaterialType,double volumn)
        { 
            List<string> headName = new List<string> { "No.\\Pозн.", "Type\\PТип", "Length\\PДужина", "Quantity\\PКоличина", "Total Length\\PУкупна дужина", "Weight\\PТежина", "Total Weight\\PУкупна маса", "Type of Material\\PВрста материјала", "C30/37" };
            int colNum= headName.Count;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                int rowNum = rebarLst.Count + 2;
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;

                    if (i == 0 || i == 3 || i == 7)
                    {
                        tb.MergeCells(CellRange.Create(tb, 0, i, 1, i));
                    }
                    else
                    {
                        string value = "(mm)";
                        if (i == 1)
                        {
                            value = "(mm)";
                        }
                        else if (i == 2)
                        {
                            value = "(cm)";
                        }
                        else if (i == 4)
                        {
                            value = "(m)";
                        }
                        else if (i == 5)
                        {
                            value = "(kg/m)";
                        }
                        else if (i == 6)
                        {
                            value = "(kg)";
                        }
                        else if (i == 8)
                        {
                            value = "(m³)";
                        }
                        tb.Cells[1, i].TextString = value; //获取i行j列数据
                        tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[1, i].Contents[0].Rotation = 0;
                        tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[1, i].Contents[0].TextStyleId = id;
                    }

                }
                for (int m = 2; m < rowNum; m++)
                {
                    Tuple<int, eDB, int, double> valueTuple; ;
                    try
                    {
                        valueTuple = rebarLst[m - 2];
                        string value = " ";
                        double dia = (int)(valueTuple.Item2);
                        for (int i = 0; i < colNum; ++i)
                        {
                            double weight = 0;// GlobalFuncs.GetUnitWeight(valueTuple.Item2);
                            double totalLength = valueTuple.Item3 * valueTuple.Item4 * 0.01;
                            switch (i)
                            {
                                case 0:
                                    value = valueTuple.Item1.ToString();
                                    break;
                                case 1:
                                    value = dia.ToString();
                                    break;
                                case 2:
                                    value = valueTuple.Item4.ToString("0.0");
                                    break;
                                case 3:
                                    value = valueTuple.Item3.ToString();
                                    break;
                                case 4:
                                    value = totalLength.ToString("0.000");
                                    break;
                                case 5:
                                    value = weight.ToString("0.000");
                                    break;
                                case 6:
                                    value = (totalLength*weight).ToString("0.0");
                                    break;
                                case 7:
                                    value = MaterialType;
                                    break;
                                case 8:
                                    value = volumn.ToString("0.0");
                                    break;
                            }
                            if (i < 7)
                            {
                                tb.Cells[m, i].TextString = value; //获取i行j列数据
                                tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m, i].Contents[0].Rotation = 0;
                                tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m, i].Contents[0].TextStyleId = id;
                            }
                            else
                            {
                                if (m == 2)
                                {
                                    tb.Cells[m, i].TextString = value; //获取i行j列数据
                                    tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                    tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m, i].Contents[0].Rotation = 0;
                                    tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m, i].Contents[0].TextStyleId = id;
                                    tb.MergeCells(CellRange.Create(tb, m, i, rowNum-1, i));
                                }
                            }
                        }

                    }

                    catch { }
                }
                #region 表格添加数据

                #endregion

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0 || i == 8)
                        tb.Columns[i].Width = 6 * 2.5 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 2.5 * scale;
                    else if (i == 7)
                        tb.Columns[i].Width = 12 * 2.5 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 8 * 2.5 * scale;
                    else
                        tb.Columns[i].Width = 10 * 2.5 * scale;
                }

                for (int i = 0; i < rowNum; ++i)
                {
                    if(i==0)
                        tb.Rows[i].Height = 12 * scale;
                    else
                        tb.Rows[i].Height = 8 * scale;
                }

                tb.LayerId = lt["H细线"];
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }


        public static void DrawPileCapCalTable(Database db, ref Extents2d ext, Point3d startPoint,
        ref double tbHeight, ref double tbWidth, string txtStyle, double scale, List<Tuple<int, eSampleType, eDB, int, double>> rebarLst, string MaterialType, double volumn, out List<Tuple<eDB, int, double>> rebarList)
        {
            rebarList = new List<Tuple<eDB, int, double>>();
            List<string> headName = new List<string> { "No.\\Pозн.", "облик и мере / shape and dimensions", "Type\\PТип", "Length\\PДужина", "Quantity\\PКоличина", "Total Length\\PУкупна дужина", "Weight\\PТежина", "Total Weight\\PУкупна маса", "Type of Material\\PВрста материјала", "C30/37" };
            int colNum = headName.Count;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                int rowNum = rebarLst.Count + 2;
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                Point2d ptSample = startPoint.C2D(6 * 2.5 * scale+20*2.5 * scale,-20*scale);
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;

                    if (i == 0 || i == 4 || i == 8)
                    {
                        tb.MergeCells(CellRange.Create(tb, 0, i, 1, i));
                    }
                    else
                    {
                        string value = "(mm)";
                        if (i == 1)
                        {
                            value = "(cm)";
                        }
                        else if (i == 2)
                        {
                            value = "(mm)";
                        }
                        else if (i == 3)
                        {
                            value = "(cm)";
                        }
                        else if (i == 5)
                        {
                            value = "(m)";
                        }
                        else if (i == 6)
                        {
                            value = "(kg/m)";
                        }
                        else if (i == 7)
                        {
                            value = "(kg)";
                        }
                        else if (i == 9)
                        {
                            value = "(m³)";
                        }
                        tb.Cells[1, i].TextString = value; //获取i行j列数据
                        tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[1, i].Contents[0].Rotation = 0;
                        tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[1, i].Contents[0].TextStyleId = id;
                    }

                }
                int numHRow = 0;
                int numLRow = 0;
                for (int m = 2; m < rowNum; m++)
                {
                    Tuple<int, eSampleType, eDB, int, double> valueTuple; ;
                    try
                    {
                        valueTuple = rebarLst[m - 2];
                        if (valueTuple.Item2 == eSampleType.UN || valueTuple.Item2 == eSampleType.UT || valueTuple.Item2 == eSampleType.UB)
                        {
                            tb.Rows[m].Height = 10 * scale;
                            SteelBarPileCap.AddLineSample2Dim(db, ptSample.C2D(0, -numLRow * 10 * scale - 4 * scale- numHRow* 25 * scale), ref ext, "H钢筋", valueTuple.Item3, valueTuple.Item2, valueTuple.Item5.ToString());
                            numLRow++;
                        }
                        else
                        {
                           
                            tb.Rows[m].Height = 25 * scale;
                            SteelBarPileCap.AddLineSample2Dim(db, ptSample.C2D(0, -numLRow * 10 * scale - 13 * scale - numHRow * 25 * scale), ref ext, "H钢筋", valueTuple.Item3, valueTuple.Item2, valueTuple.Item5.ToString());
                            numHRow++;
                        }
                      
                        double dia = (int)(valueTuple.Item3);
                        double valueLen = dia;
                        if (dia > 16)
                            valueLen = dia * 1.4;
                        else
                            valueLen = dia * 1.25;
                        double length = valueTuple.Item5;
                        if (valueTuple.Item2 != eSampleType.UN)
                        {
                            length += 2 * valueLen;
                        }
                        Tuple<eDB, int, double> tu = new Tuple<eDB, int, double>(valueTuple.Item3, valueTuple.Item4, length);
                        rebarList.Add(tu);
                        string value = " ";
                        for (int i = 0; i < colNum; ++i)
                        {
                            double weight = GlobalFuncs.GetUnitWeight(valueTuple.Item3);
                           
                            double totalLength = valueTuple.Item4 * length * 0.01;
                            switch (i)
                            {
                                case 0:
                                    value = valueTuple.Item1.ToString();
                                    break;
                                case 2:
                                    value = dia.ToString();
                                    break;
                                case 3:
                                    value = length.ToString("0.0");
                                    break;
                                case 4:
                                    value = valueTuple.Item4.ToString();
                                    break;
                                case 5:
                                    value = totalLength.ToString("0.000");
                                    break;
                                case 6:
                                    value = weight.ToString("0.000");
                                    break;
                                case 7:
                                    value = (totalLength * weight).ToString("0.0");
                                    break;
                                case 8:
                                    value = MaterialType;
                                    break;
                                case 9:
                                    value = volumn.ToString("0.0");
                                    break;
                            }
                            if (i < 8)
                            {
                                if (i != 1)
                                {
                                    tb.Cells[m, i].TextString = value; //获取i行j列数据
                                    tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                    tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m, i].Contents[0].Rotation = 0;
                                    tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m, i].Contents[0].TextStyleId = id;
                                }
                                else
                                {
                                    tb.Cells[m, i].TextString = " "; //获取i行j列数据
                                    tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                    tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m, i].Contents[0].Rotation = 0;
                                    tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m, i].Contents[0].TextStyleId = id;
                                  
                                    
                                }
                            }
                            else
                            {
                                if (m == 2)
                                {
                                    tb.Cells[m, i].TextString = value; //获取i行j列数据
                                    tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                    tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m, i].Contents[0].Rotation = 0;
                                    tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m, i].Contents[0].TextStyleId = id;
                                    tb.MergeCells(CellRange.Create(tb, m, i, rowNum - 1, i));
                                }
                            }
                        }

                    }

                    catch { }
                }
                #region 表格添加数据

                #endregion

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0 || i == 9)
                        tb.Columns[i].Width = 6 * 2.5 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 40 * 2.5 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 5 * 2.5 * scale;
                    else if (i == 8)
                        tb.Columns[i].Width = 12 * 2.5 * scale;
                    else if (i == 4)
                        tb.Columns[i].Width = 8 * 2.5 * scale;
                    else
                        tb.Columns[i].Width = 10 * 2.5 * scale;
                }

                for (int i = 0; i < rowNum; ++i)
                {
                    if (i == 0)
                        tb.Rows[i].Height = 12 * scale;
                    else if (i == 1)
                        tb.Rows[i].Height = 8 * scale;
                    //else
                    //    tb.Rows[i].Height = 10 * scale;
                }

                tb.LayerId = lt["H细线"];
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }
        public static void DrawPileCapCalNewTable(Database db, ref Extents2d ext, Point3d startPoint,
   ref double tbHeight, ref double tbWidth, string txtStyle, double scale, List<Tuple<int, eSampleType, eDB, int, double>> rebarLst, string MaterialType, double volumn, out List<Tuple<eDB, int, double>> rebarList)
        {
            rebarList = new List<Tuple<eDB, int, double>>();
            List<string> headName = new List<string> { "озн./\\Pitem", "облик и мере / shape and dimensions\\P[cm]", "B 500B\\P%%C", "дужина / \\Plength[m]", "n\\P[kom/pcs]", "n x дужина /\\Pn x length[m]"};
            int colNum = headName.Count;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                int rowNum = rebarLst.Count + 3;
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                Point2d ptSample = startPoint.C2D(6 * 2.5 * scale + 20 * 2.5 * scale, -28 * scale);
                tb.Cells[0,0].TextString = "Šipke - specifikacija / Reinf.bars - specification"; //获取i行j列数据
                tb.Cells[0,0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0,0].Alignment = CellAlignment.MiddleLeft;
                tb.Cells[0,0].Contents[0].Rotation = 0;
                tb.Cells[0,0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0,0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 0, 0, 0, colNum-1));
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                tb.Cells[2, 0].TextString = "Наглавна греда стуба P41-1 / Pile cap of pier P41-1(24 kom)"; //获取i行j列数据
                tb.Cells[2, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 0].Contents[0].Rotation = 0;
                tb.Cells[2, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[2, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2, 0, 2, colNum - 1));
                int numHRow = 0;
                int numLRow = 0;
                for (int m = 3; m < rowNum; m++)
                {
                    Tuple<int, eSampleType, eDB, int, double> valueTuple; ;
                    try
                    {
                        valueTuple = rebarLst[m - 3];
                        if (valueTuple.Item2 == eSampleType.UN || valueTuple.Item2 == eSampleType.UT || valueTuple.Item2 == eSampleType.UB)
                        {
                            tb.Rows[m].Height = 10 * scale;
                            SteelBarPileCap.AddLineSample2Dim(db, ptSample.C2D(0, -numLRow * 10 * scale - 4 * scale - numHRow * 25 * scale), ref ext, "H钢筋", valueTuple.Item3, valueTuple.Item2, valueTuple.Item5.ToString());
                            numLRow++;
                        }
                        else
                        {

                            tb.Rows[m].Height = 25 * scale;
                            SteelBarPileCap.AddLineSample2Dim(db, ptSample.C2D(0, -numLRow * 10 * scale - 13 * scale - numHRow * 25 * scale), ref ext, "H钢筋", valueTuple.Item3, valueTuple.Item2, valueTuple.Item5.ToString());
                            numHRow++;
                        }

                        double dia = (int)(valueTuple.Item3);
                        double valueLen = dia;
                        if (dia > 16)
                            valueLen = dia * 1.4;
                        else
                            valueLen = dia * 1.25;
                        double length = valueTuple.Item5;
                        if (valueTuple.Item2 != eSampleType.UN)
                        {
                            length += 2 * valueLen;
                        }
                        Tuple<eDB, int, double> tu = new Tuple<eDB, int, double>(valueTuple.Item3, valueTuple.Item4, length);
                        rebarList.Add(tu);
                        string value = " ";
                        for (int i = 0; i < colNum; ++i)
                        {
                            double weight = GlobalFuncs.GetUnitWeight(valueTuple.Item3);

                            double totalLength = valueTuple.Item4 * length * 0.01;
                            switch (i)
                            {
                                case 0:
                                    value = valueTuple.Item1.ToString();
                                    break;
                                case 2:
                                    value = dia.ToString();
                                    break;
                                case 3:
                                    value = length.ToString("0.0");
                                    break;
                                case 4:
                                    value = valueTuple.Item4.ToString();
                                    break;
                                case 5:
                                    value = totalLength.ToString("0.000");
                                    break;
                                    //case 6:
                                    //    value = weight.ToString("0.000");
                                    //    break;
                                    //case 7:
                                    //    value = (totalLength * weight).ToString("0.0");
                                    //    break;
                                    //case 8:
                                    //    value = MaterialType;
                                    //    break;
                                    //case 9:
                                    //    value = volumn.ToString("0.0");
                                    //    break;
                            }
                            //if (i < 8)
                            //{
                            if (i != 1)
                            {
                                tb.Cells[m, i].TextString = value; //获取i行j列数据
                                tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m, i].Contents[0].Rotation = 0;
                                tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m, i].Contents[0].TextStyleId = id;
                            }
                            else
                            {
                                tb.Cells[m, i].TextString = " "; //获取i行j列数据
                                tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m, i].Contents[0].Rotation = 0;
                                tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m, i].Contents[0].TextStyleId = id;


                            }
                        }
                          

                    }

                    catch { }
                }
                #region 表格添加数据

                #endregion

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0 )
                        tb.Columns[i].Width = 6 * 2.5 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 40 * 2.5 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 5 * 2.5 * scale;                
                    else if (i == 4)
                        tb.Columns[i].Width = 8 * 2.5 * scale;
                    else
                        tb.Columns[i].Width = 10 * 2.5 * scale;
                }

                for (int i = 0; i < rowNum; ++i)
                {
                    if (i == 0)
                        tb.Rows[i].Height = 8 * scale;
                   else if (i == 1)
                        tb.Rows[i].Height = 12 * scale;
                    else if (i == 2)
                        tb.Rows[i].Height = 8 * scale;
                    //else
                    //    tb.Rows[i].Height = 10 * scale;
                }

                tb.LayerId = lt["H细线"];
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }

        public static void DrawPileCapCalMergeTable(Database db, ref Extents2d ext, Point3d startPoint,
       ref double tbHeight, ref double tbWidth, string txtStyle, double scale, List<Tuple<eDB, int, double>> rebarLst, List<eDB> dbLst, string MaterialType, string concrete_no, double volumn, out List<Tuple<eDB, int, double>> rebarList)
        {
            rebarList = new List<Tuple<eDB, int, double>>();
            List<string> headName = new List<string> { "%%C\\[mm]", "Укупна дужина / Total length\\P[m]", "Јединична тежина /\\PUnit weight [kg/m']", "Težina / Weight\\P[kg]" };
            int colNum = headName.Count;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                int rowNum = dbLst.Count + 5;
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
              
                tb.Cells[0,0].TextString = "Šipke - rekapitulacija"; //获取i行j列数据
                tb.Cells[0,0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0,0].Alignment = CellAlignment.MiddleLeft;
                tb.Cells[0,0].Contents[0].Rotation = 0;
                tb.Cells[0,0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0,0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 0, 0, 0, colNum-1));

                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;                  
                }

                tb.Cells[2, 0].TextString = MaterialType; //获取i行j列数据
                tb.Cells[2, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 0].Contents[0].Rotation = 0;
                tb.Cells[2, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[2, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2, 0, 2, colNum - 1));



                string value = "";
                double totalLength = 0;
                double totalWeight = 0;
                double AllWeight = 0;
                for (int m = 3; m <dbLst.Count+3 ; m++)
                {
                    double weight = GlobalFuncs.GetUnitWeight(dbLst[m-3]);
                    List<Tuple<eDB, int, double>> newLst= rebarLst.FindAll(o => o.Item1 == dbLst[m - 3]);
                    if(newLst.Count>0)
                    {
                        foreach(Tuple<eDB, int, double> item in newLst)
                        {
                            totalLength += item.Item3 * 0.01*item.Item2;
                            totalWeight += weight * item.Item3*0.01 * item.Item2;
                        }
                    }
                    AllWeight += totalWeight;
                    try
                    {
                        for (int i = 0; i < colNum; ++i)
                        {
                            switch (i)
                            {
                                case 0:
                                    value = ((int)dbLst[m - 3]).ToString();
                                    break;
                                case 1:
                                    value = totalLength.ToString("0.000");
                                    break;
                                case 2:
                                    value = weight.ToString("0.000");
                                    break;
                                case 3:
                                    value = totalWeight.ToString("0.0");
                                    break;
                            }
                            tb.Cells[m, i].TextString = value; //获取i行j列数据
                            tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m, i].Contents[0].Rotation = 0;
                            tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m, i].Contents[0].TextStyleId = id;
                        }
                    }

                    catch { }
                }

                tb.Cells[rowNum-2,0].TextString = "Укупно / Total(B500)"; //获取i行j列数据
                tb.Cells[rowNum-2,0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rowNum-2,0].Alignment = CellAlignment.MiddleLeft;
                tb.Cells[rowNum-2,0].Contents[0].Rotation = 0;
                tb.Cells[rowNum-2,0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[rowNum-2,0].Contents[0].TextStyleId = id;
 
                tb.Cells[rowNum-2,3].TextString = AllWeight.ToString("0.0"); //获取i行j列数据
                tb.Cells[rowNum-2,3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rowNum-2,3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[rowNum-2,3].Contents[0].Rotation = 0;
                tb.Cells[rowNum-2,3].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[rowNum-2,3].Contents[0].TextStyleId = id;
                tb.Cells[rowNum - 2, 1].TextString = " "; //获取i行j列数据
                tb.Cells[rowNum - 2, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rowNum - 2, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[rowNum - 2, 1].Contents[0].Rotation = 0;
                tb.Cells[rowNum - 2, 1].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[rowNum - 2, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, rowNum - 2, 1, rowNum - 2, 2));

                tb.Cells[rowNum - 1,0].TextString = concrete_no+ "(m³)"; //获取i行j列数据
                tb.Cells[rowNum - 1,0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rowNum - 1,0].Alignment = CellAlignment.MiddleLeft;
                tb.Cells[rowNum - 1,0].Contents[0].Rotation = 0;
                tb.Cells[rowNum - 1,0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[rowNum - 1,0].Contents[0].TextStyleId = id;
                                    
                tb.Cells[rowNum - 1,1].TextString = volumn.ToString(); //获取i行j列数据
                tb.Cells[rowNum - 1,1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rowNum - 1,1].Alignment = CellAlignment.MiddleRight;
                tb.Cells[rowNum - 1,1].Contents[0].Rotation = 0;
                tb.Cells[rowNum - 1,1].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[rowNum - 1,1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, rowNum - 1, 1, rowNum - 1, colNum - 1));
                #region 表格添加数据

                #endregion

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0 )
                        tb.Columns[i].Width = 20 * 2.5 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 30 * 2.5 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 17 * 2.5 * scale;                    
                    else
                        tb.Columns[i].Width = 12 * 2.5 * scale;
                }

                for (int i = 0; i < rowNum; ++i)
                {
                    if (i == 1)
                        tb.Rows[i].Height = 15 * scale;
                    else 
                        tb.Rows[i].Height = 8 * scale;
                }

                tb.LayerId = lt["H细线"];
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }
    }
}
